import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../index.dart';
import 'widgets.dart';
import 'package:leader_help/utils/util.dart';

class ProvinceLevelCell extends GetView<ProvinceLevelController> {
  const ProvinceLevelCell({
    Key? key,
    required this.mods,
    required this.title,
  }) : super(key: key);
  final List<ProvinceDiffItemModel> mods;
  final String title;
  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 10.r),
      decoration: BoxDecoration(
          color: Colors.white,
          border: Border.all(color: ColorsUtil.content, width: 0.5)),
      child: Column(
        children: _getItems(title),
      ),
    );
  }

  List<Widget> _getItems(String title) {
    List<Widget> _items = [
      _getTitleItem(title),
    ];
    _items.addAll(mods.map((e) => _getItem(e)).toList());
    return _items;
  }

  Widget _getTitleItem(String title) {
    var _mod = controller.state.mod;
    var _levelMod = controller.state.levelMod;
    return Container(
      decoration: const BoxDecoration(
        border:
            Border(bottom: BorderSide(color: ColorsUtil.content, width: 0.5)),
      ),
      height: 40.r,
      // constraints: BoxConstraints(minHeight: 50.r),
      child: Row(
        children: [
          Expanded(
            flex: 2,
            child: Container(
              // padding: EdgeInsets.all(10.r),
              alignment: Alignment.center,
              child: Text(
                title,
                textAlign: TextAlign.center,
                style: pfMediumStyle(color: ColorsUtil.title, fontSize: 14.sp),
              ),
            ),
          ),
          Expanded(
            child: Container(
              decoration: const BoxDecoration(
                border: Border(
                  left: BorderSide(color: ColorsUtil.content, width: 0.5),
                ),
              ),
              alignment: Alignment.center,
              child: RichText(
                text: TextSpan(
                    text: _mod.provinceName,
                    style:
                        pfMediumStyle(color: ColorsUtil.title, fontSize: 14.sp),
                    children: [
                      TextSpan(
                        text: '(本省)',
                        style: pfMediumStyle(
                            color: ColorsUtil.orange, fontSize: 14.sp),
                      )
                    ]),
              ),
            ),
          ),
          Expanded(
            child: Container(
              decoration: const BoxDecoration(
                border: Border(
                    left: BorderSide(color: ColorsUtil.content, width: 0.5)),
              ),
              alignment: Alignment.center,
              child: Text(
                _levelMod.provinceName,
                style: pfMediumStyle(color: ColorsUtil.title, fontSize: 14.sp),
              ),
            ),
          ),
        ],
      ),
    );
  }

  Widget _getItem(ProvinceDiffItemModel mod) {
    return GestureDetector(
      onTap: () => controller.actionCellItem(mod.name),
      child: Container(
        decoration: const BoxDecoration(
          border:
              Border(bottom: BorderSide(color: ColorsUtil.content, width: 0.5)),
        ),
        height: 55.r,
        // constraints: BoxConstraints(minHeight: 50.r),
        child: Row(
          children: [
            Expanded(
              flex: 2,
              child: Container(
                // padding: EdgeInsets.all(10.r),
                alignment: Alignment.center,
                child: Text(
                  mod.name,
                  textAlign: TextAlign.center,
                  style: pfMediumStyle(
                      color: mod.isLack ? ColorsUtil.red : ColorsUtil.title,
                      fontSize: 13.sp),
                ),
              ),
            ),
            Expanded(
              child: Container(
                decoration: const BoxDecoration(
                  border: Border(
                    left: BorderSide(color: ColorsUtil.content, width: 0.5),
                  ),
                ),
                alignment: Alignment.center,
                child: Icon(
                  mod.isLack
                      ? IconUtil.circle_wrong
                      : Icons.check_circle_outline,
                  size: 20.r,
                  color: mod.isLack ? ColorsUtil.red : ColorsUtil.green,
                ),
              ),
            ),
            Expanded(
              child: Container(
                decoration: const BoxDecoration(
                  border: Border(
                      left: BorderSide(color: ColorsUtil.content, width: 0.5)),
                ),
                alignment: Alignment.center,
                child: Icon(
                  mod.isLack2 == true
                      ? IconUtil.circle_wrong
                      : Icons.check_circle_outline,
                  size: 20.r,
                  color:
                      mod.isLack2 == true ? ColorsUtil.red : ColorsUtil.green,
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
